package com.bieyang.anjia.ui.widget;

import com.bieyang.anjia.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.ImageView;

@SuppressLint("DrawAllocation")
public class MyImg extends ImageView {
	Context context;
	float backShadowWidth;
	float lineWidth;
	float LineLength;

	public MyImg(Context context) {
		super(context);
	}

	public MyImg(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public MyImg(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		TypedArray a = context.obtainStyledAttributes(attrs,
				R.styleable.MyImgView);
		backShadowWidth = a.getDimension(R.styleable.MyImgView_backShadowWidth,
				10.0f);
		lineWidth = a.getDimension(R.styleable.MyImgView_lineWidth, 5.0f);
		LineLength = a.getDimension(R.styleable.MyImgView_lineLength, 30.0f);
		a.recycle();

	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		int width = canvas.getWidth();
		int height = canvas.getHeight();
		Paint paint = new Paint(0);
		paint.setColor(Color.BLACK);
		paint.setAlpha(50);
		canvas.drawRect(0, 0, width, backShadowWidth, paint);
		canvas.drawRect(0, backShadowWidth, backShadowWidth, height, paint);
		canvas.drawRect(width - backShadowWidth, backShadowWidth, width, height
				- backShadowWidth, paint);
		canvas.drawRect(backShadowWidth, height - backShadowWidth, width,
				height, paint);
		paint.setColor(Color.GREEN);
		paint.setAlpha(100);
		canvas.drawRect(backShadowWidth, backShadowWidth, LineLength
				+ backShadowWidth, backShadowWidth + lineWidth, paint);
		canvas.drawRect(backShadowWidth, backShadowWidth + lineWidth, lineWidth
				+ backShadowWidth, LineLength + backShadowWidth, paint);
		canvas.drawRect(backShadowWidth, height - backShadowWidth - LineLength,
				backShadowWidth + lineWidth, height - backShadowWidth, paint);
		canvas.drawRect(backShadowWidth + lineWidth, height - backShadowWidth
				- lineWidth, backShadowWidth + LineLength, height
				- backShadowWidth, paint);
		canvas.drawRect(width - backShadowWidth - LineLength, backShadowWidth,
				width - backShadowWidth, backShadowWidth + lineWidth, paint);
		canvas.drawRect(width - backShadowWidth - lineWidth, backShadowWidth
				+ lineWidth, width - backShadowWidth, backShadowWidth
				+ LineLength, paint);
		canvas.drawRect(width - backShadowWidth - lineWidth, height
				- backShadowWidth - LineLength, width - backShadowWidth, height
				- backShadowWidth - lineWidth, paint);
		canvas.drawRect(width - backShadowWidth - LineLength, height
				- backShadowWidth - lineWidth, width - backShadowWidth, height
				- backShadowWidth, paint);

	}
}
